package com.tzx.lifehousekeeper.service;

import com.tzx.lifehousekeeper.model.dto.UserDto;
import com.tzx.lifehousekeeper.model.entity.UserEntity;
import com.tzx.lifehousekeeper.repository.UserRepository;
import com.tzx.lifehousekeeper.utils.UuidUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author tuzongxun
 * @Date 2021/9/22
 */
@Service
public class UserService {

	@Autowired
	private UserRepository userRepository;

	public List<UserDto> findUsers(){
		List<UserDto> list=userRepository.findUser();
		//list.stream().map(u->{
		//	SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
		//	simpleDateFormat.format();
		//	u.getBirthday()
		//})
		return list;
	}

	public String addUser(UserDto userDto){
		String uid=UuidUtil.createDbId();
		UserEntity userEntity=new UserEntity();
		BeanUtils.copyProperties(userDto,userEntity);
		userEntity.setId(uid);
		userEntity.setCreateTime(new Date());
		userEntity.setUpdateTime(new Date());
		userRepository.addUser(userEntity);
		return uid;
	}
}
